package net.mingsoft.basic.realm;

import org.apache.shiro.realm.*;
import org.apache.shiro.authc.*;
import org.apache.shiro.authc.credential.*;
import org.apache.shiro.subject.*;
import org.apache.shiro.cache.*;
import org.apache.shiro.authz.*;
import java.util.*;

public abstract class BaseAuthRealm extends AuthorizingRealm
{
    public BaseAuthRealm() {
        this.setAuthenticationTokenClass((Class)UsernamePasswordToken.class);
        this.setCredentialsMatcher((CredentialsMatcher)new SimpleCredentialsMatcher());
    }
    
    public void clearCachedAuthorizationInfo(final String principal) {
        final SimplePrincipalCollection principals = new SimplePrincipalCollection((Object)principal, this.getName());
        this.clearCachedAuthorizationInfo((PrincipalCollection)principals);
    }
    
    public void clearAllCachedAuthorizationInfo() {
        final Cache<Object, AuthorizationInfo> cache = (Cache<Object, AuthorizationInfo>)this.getAuthorizationCache();
        if (cache != null) {
            for (final Object key : cache.keys()) {
                cache.remove(key);
            }
        }
    }
}
